function capacity = disk_capacity_dos

%  Author : Jeffrey O'Dell
%  Platform : Win32, Matlab v6.5 R13
%  Date : January 21, 2004
%  Summary : This snippet uses the DOS command dir under Win2k knowingly
%  counts where the amount of free disk space will be located within the
%  one dimensional array.  The amount is excised into its own string
%  'capacity' and can be used accordingly.

%  NOTE:  Would we have to do this for each platform?  Perhaps I should
%  look into 'system' calls.

if isunix
    fprintf('Not implemented yet.\n');
else
    % Get the directory string
    [s, w] = dos('dir');             % NOTE: Will not compile here.
    test = strfind(w,'Dir(s)');      % Find the known string.
    test = test + 8;                 % Move ahead appropriately.
    capacity = w(test:length(w));    % Snip.
    %disp(capacity);
    separated = strread(capacity, '%s');
    num = separated(1);
    num = char(num);

    % Create an nx1 array of the digits, delimited by commas
    num = strread(num,'%s','delimiter',',');
    [count, blah] = size(num);
    
    current = num(1);
    for i = 2:count
        current = strcat(current,num(i));
    end

    % Convert to a number
    current = char(current);
    current = str2num(current);
    %disp(current)

    final = current / 1000000000;
    if final >= 1
        capacity = sprintf('%.2f GiB free.\n',final);
    else if (final * 1000) < 1
            final = final * 1000 * 1000;
            capacity = sprintf('%.2f KiB free.\n',final);
        else
            final = final * 1000;
            capacity = sprintf('%.2f MiB free.\n',final);
        end
    end
    
end
